//
//  STStatusPictureViewCell.m
//  OCVVeibo
//
//  Created by leergou on 16/7/29.
//  Copyright © 2016年 WhiteHouse. All rights reserved.
//

#import "STStatusPictureViewCell.h"
#import "STStatusPictureInfo.h"
#import "UIImage+GIF.h"


@interface STStatusPictureViewCell ()

// imageView
@property (nonatomic,strong) UIImageView *imageView;
// gifLogo
@property (nonatomic,strong) UIImageView *gifLogo;

@end


@implementation STStatusPictureViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    return self;
}

#pragma mark - setupUI
- (void)setupUI{
    // 添加子控件
    [self.contentView addSubview:self.imageView];
    [self.contentView addSubview:self.gifLogo];
    
    // 设置约束
    [self.imageView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).offset(UIEdgeInsetsZero);
    }];
    
    [self.gifLogo makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.bottom);
        make.trailing.equalTo(self.contentView.trailing);
    }];
}

#pragma mark - 重写图片信息模型的set 方法,分发数据
- (void)setPictureInfo:(STStatusPictureInfo *)pictureInfo{
    /*
     - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
     
     UIImage *image = [UIImage sd_animatedGIFNamed:@"1"];
     
     self.imageView.image = image;
     }
     */
    
    _pictureInfo = pictureInfo;
    
#warning - gif 动图显示有问题
    if ([pictureInfo.thumbnail_pic hasSuffix:@".gif"]) {
//        UIImage *gifImage = [UIImage imagewith];
        NSURL *gifUrl = [NSURL URLWithString:pictureInfo.thumbnail_pic];
//        NSData *gifData = [[NSData alloc] initWithContentsOfURL:gifUrl];
//        UIImage *gifImage = [UIImage sd_animatedGIFWithData:gifData];
        NSArray *gifArra = @[gifUrl];
        [self.imageView sd_setAnimationImagesWithURLs:gifArra];
        self.gifLogo.hidden = NO;
    } else {
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:pictureInfo.thumbnail_pic]];
        self.gifLogo.hidden = YES;
    }
    
}

#pragma mark - lazy
- (UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
    }
    return _imageView;
}

- (UIImageView *)gifLogo{
    if (!_gifLogo) {
        _gifLogo = [[UIImageView alloc] initWithImageName:@"timeline_image_gif"];
    }
    return  _gifLogo;
}





@end













